using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;

public class UISlider : MonoBehaviour
{
    public GameObject fill;
    public Person usingP;

    [SerializeField]
    float plan = 0;
    public float Plan
    {
        get => plan;
        set
        {
            plan = value;
            if (fill != null)
            {
                fill.transform.localPosition = new((plan / 100 / 2) - 0.5f, 0, 0);
                fill.transform.localScale = new(plan / 100, 1, 1);
            }
        }
    }

    private void Awake()
    {
        uis = this;
        uis.gameObject.SetActive(false);
    }

    private void Update()
    {
        fill.transform.localPosition = new((plan * 5) - 500, 0, 0);
        fill.transform.localScale = new(plan / 100, 1, 1);
        if (PlayerContral.Instance.P_contral != usingP)
            uis.gameObject.SetActive(false);
    }

    //static------
    public static UISlider uis;

    public static void Set(Person p, float plan)
    {
        if (PlayerContral.Instance.P_contral == p)
        {
            uis.plan = plan;
            uis.usingP = p;
            uis.gameObject.SetActive(true);
        }
    }

    public static void Close(Person p)
    {
        if (PlayerContral.Instance.P_contral == p)
            uis.gameObject.SetActive(false);
    }
}
